﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace Projeto2012._1_Desktop_Cabeceira
{
    public partial class ListarLivros : Form
    {
        private CookieContainer cont = new CookieContainer();
        public ListarLivros(CookieContainer c)
        {
            this.cont = c;
            InitializeComponent();
            this.listarLivros();
        }

        private void listarLivros()
        {
            try
            {
                string uri = "http://localhost:9000/admin/listarlivros";
                HttpWebRequest req = WebRequest.Create(uri) as HttpWebRequest;
                req.Accept = "text/xml";
                req.CookieContainer = cont;
                req.KeepAlive = false;
                
                using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse)
                {
                    // Carrega os dados da reposta em um dataset  
                    DataSet dsLivros = new DataSet();
                    dsLivros.ReadXml(resp.GetResponseStream());
                    dataGridView1.DataSource = dsLivros.Tables[0];
                    dataGridView1.Columns[0].Width = 250;
                    dataGridView1.Columns[0].HeaderText = "Livro";
                    resp.Close();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());    
            }
        }

        private void buttonAtualizar_Click(object sender, EventArgs e)
        {
            listarLivros();
        }

        
 
    }
}
